<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<% pageContext.setAttribute("newLineChar", "\n"); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Search</title>
        ${stylesheet}
        ${jquery}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content search-content">
                <h1>Search results</h1>
                <div class="full-block">
                    You have searched with the keyword(s): ${keywords}
                </div>
                <div class="margin-bottom-20"></div>
                <div class="full-block">
                    <h4 class="search">Search in courses</h4>
                    <c:choose>
                        <c:when test="${fn:length(results_courses) > 0}">
                            <table class="overview">
                                <tr>
                                    <th>Name</th>
                                    <th>Description</th>
                                </tr>
                                <c:set var="i" value="0"/>
                                <c:forEach items="${results_courses}" var="course">
                                    <c:set var="i" value="${i + 1}"/>
                                    <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                        <td width="25%">
                                            <a href="${url}Course?courseid=${course.id}" class="hidden"></a>
                                            ${course.name}
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(course.description) > 70}">
                                                     <c:out value="${fn:substring(course.description, 0, 70)}"/>...
                                                </c:when>
                                                <c:otherwise>
                                                    ${course.description}
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </c:when>
                        <c:otherwise>
                            <div class="no-yet-message">
                                <center>We did not found any results. Please try with different keywords.</center>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="margin-bottom-20"></div>
                <div class="full-block">
                    <h4 class="search">Search in students</h4>
                    <c:choose>
                        <c:when test="${fn:length(results_students) > 0}">
                            <table class="overview">
                                <tr>
                                    <th>Full name</th>
                                    <th>Interests</th>
                                </tr>
                                <c:set var="i" value="0"/>
                                <c:forEach items="${results_students}" var="student">
                                    <c:set var="i" value="${i + 1}"/>
                                    <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                        <td width="25%">
                                            <a href="${url}userProfile?id=${student.id}" class="hidden"></a>
                                            ${student.firstname} ${student.insertion} ${student.lastname}
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(student.interests) > 70}">
                                                     <c:out value="${fn:substring(student.interests, 0, 70)}"/>...
                                                </c:when>
                                                <c:otherwise>
                                                    ${student.interests}
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </c:when>
                        <c:otherwise>
                            <div class="no-yet-message">
                                <center>We did not found any results. Please try with different keywords.</center>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="margin-bottom-20"></div>
                <div class="full-block">
                    <h4 class="search">Search in teachers</h4>
                    <c:choose>
                        <c:when test="${fn:length(results_teachers) > 0}">
                            <table class="overview">
                                <tr>
                                    <th>Full name</th>
                                    <th>Interests</th>
                                </tr>
                                <c:set var="i" value="0"/>
                                <c:forEach items="${results_teachers}" var="teacher">
                                    <c:set var="i" value="${i + 1}"/>
                                    <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                        <td width="25%">
                                            <a href="${url}userProfile?id=${teacher.id}" class="hidden"></a>
                                            ${teacher.firstname} ${teacher.insertion} ${teacher.lastname}
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(teacher.interests) > 70}">
                                                     <c:out value="${fn:substring(teacher.interests, 0, 70)}"/>...
                                                </c:when>
                                                <c:otherwise>
                                                    ${teacher.interests}
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </c:when>
                        <c:otherwise>
                            <div class="no-yet-message">
                                <center>We did not found any results. Please try with different keywords.</center>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="margin-bottom-20"></div>
                <div class="full-block">
                    <h4 class="search">Search in pages</h4>
                    <c:choose>
                        <c:when test="${fn:length(results_pages) > 0}">
                            <table class="overview">
                                <tr>
                                    <th>Title</th>
                                    <th>Content</th>
                                </tr>
                                <c:set var="i" value="0"/>
                                <c:forEach items="${results_pages}" var="page">
                                    <c:set var="i" value="${i + 1}"/>
                                    <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                        <td width="25%">
                                            <a href="${url}Page?p=${page.title}" class="hidden"></a>
                                            ${page.title}
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(page.content) > 70}">
                                                     <c:out value="${fn:substring(page.content, 0, 70)}"/>...
                                                </c:when>
                                                <c:otherwise>
                                                    <c:out value="${page.content}"/>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </c:when>
                        <c:otherwise>
                            <div class="no-yet-message">
                                <center>We did not found any results. Please try with different keywords.</center>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="margin-bottom-20"></div>
                <c:if test="${pm eq 'true'}">
                    <div class="full-block">
                        <h4 class="search">Search in private messages</h4>
                        <c:choose>
                            <c:when test="${fn:length(results_private_messages) > 0}">
                                <table class="overview">
                                    <tr>
                                        <th>From</th>
                                        <th>To</th>
                                        <th>Subject</th>
                                        <th>Folder</th>
                                    </tr>
                                    <c:set var="i" value="0"/>
                                    <c:forEach items="${results_private_messages}" var="private_message">
                                        <c:set var="i" value="${i + 1}"/>
                                        <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                            <td width="25%">
                                                <a href="${url}ComposePrivateMessage?message=${private_message.id}&action=view" class="hidden"></a>
                                                ${private_message.sender.firstname} ${private_message.sender.insertion} ${private_message.sender.lastname}
                                            </td>
                                            <td width="25%">
                                                ${private_message.receiver.firstname} ${private_message.receiver.insertion} ${private_message.receiver.lastname}
                                            </td>
                                            <td width="40%">
                                                <c:choose>
                                                    <c:when test="${fn:length(private_message.subject) > 35}">
                                                         <c:out value="${fn:substring(private_message.subject, 0, 35)}"/>...
                                                    </c:when>
                                                    <c:otherwise>
                                                        ${private_message.subject}
                                                    </c:otherwise>
                                                </c:choose>
                                            </td>
                                            <td width="10%">
                                                <c:choose>
                                                    <c:when test="${private_message.folder eq 2}">
                                                        Outbox
                                                    </c:when>
                                                    <c:when test="${private_message.folder eq 3}">
                                                        Trash
                                                    </c:when>
                                                    <c:otherwise>
                                                        Inbox
                                                    </c:otherwise>
                                                </c:choose>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </table>
                            </c:when>
                            <c:otherwise>
                                <div class="no-yet-message">
                                    <center>We did not found any results. Please try with different keywords.</center>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </c:if>
                <div class="margin-bottom-10"></div>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
